package com.kob.backend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kob.backend.mapper.SeatRecordMapper;
import com.kob.backend.pojo.SeatRecord;
import com.kob.backend.service.user.SeatRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SeatRecordServiceImpl implements SeatRecordService {
    @Autowired
    private SeatRecordMapper seatRecordMapper;

    @Override
    public boolean userHasDue(String userid, String selectedDateSlot, String selectedTimeSlot) {
        QueryWrapper<SeatRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user", userid);
        queryWrapper.eq("dateslot", selectedDateSlot);
        queryWrapper.eq("timeslot", selectedTimeSlot);
        return seatRecordMapper.exists(queryWrapper);
    }

    @Override
    public boolean seatHasDue(int seatId, String selectedDateSlot, String selectedTimeSlot) {
        QueryWrapper<SeatRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("seatid", seatId);
        queryWrapper.eq("dateslot", selectedDateSlot);
        queryWrapper.eq("timeslot", selectedTimeSlot);
        return seatRecordMapper.exists(queryWrapper);
    }

    @Override
    public boolean seatUserHasDue(int seatId, String userid, String selectedDateSlot, String selectedTimeSlot) {
        QueryWrapper<SeatRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user", userid);
        queryWrapper.eq("seatid", seatId);
        queryWrapper.eq("dateslot", selectedDateSlot);
        queryWrapper.eq("timeslot", selectedTimeSlot);
        return seatRecordMapper.exists(queryWrapper);
    }

    @Override
    public int save(SeatRecord data) {
        return seatRecordMapper.insert(data);
    }

    @Override
    public int delete(SeatRecord data) {
        QueryWrapper<SeatRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("seatid", data.getSeatId());
        queryWrapper.eq("dateslot", data.getDateSlot());
        queryWrapper.eq("timeslot", data.getTimeSlot());
        return seatRecordMapper.delete(queryWrapper);
    }
}
